/**
 * Copyright (C), 2015-2020, 东华云有限公司
 * FileName: WebSecurityConfig
 * Author:   Hezeyu
 * Date:     2020/7/27 15:03
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * Hezeyu           2020/7/27 15:03   1.0
 */
package eureka.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;

/**
 * 〈一句话功能简述〉<br> 
 * 〈〉
 *
 * @author Hezeyu
 * @create 2020/7/27
 * @since 1.0.0
 */
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    /**
     * 高版本的丢弃了
     *
     * security:
     *   basic:
     *    enabled: true
     *
     * 配置，应该使用以下方式开启
     *
     * @param http
     * @throws Exception
     */
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        // Configure HttpSecurity as needed (e.g. enable http basic).
        http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER);
        http.csrf().disable();
        //注意：为了可以使用 http://${user}:${password}@${host}:${port}/eureka/ 这种方式登录,所以必须是httpBasic,
        // 如果是form方式,不能使用url格式登录
        http.authorizeRequests().anyRequest().authenticated().and().httpBasic();
    }
}
